{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Kanerva's Figure 1.2 (page 25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calculate_probabilities():\n",
    "    from math import factorial\n",
    "    comb = lambda a, b: factorial(a)/factorial(b)/factorial(a-b)\n",
    "    acc = [0]\n",
    "    for i in xrange(1001):\n",
    "        acc.append(acc[-1] + comb(1000, i))\n",
    "    x = range(0, 1001)\n",
    "    y = [acc[i]/float(2**1000) for i in xrange(1001)]\n",
    "    return x, y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "x, y = calculate_probabilities()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(421, 2.34855463163212e-07),\n",
       " (422, 3.2683072799845206e-07),\n",
       " (423, 4.5302427856623403e-07),\n",
       " (424, 6.254589646848581e-07),\n",
       " (425, 8.601165446151555e-07),\n",
       " (426, 1.178146582355982e-06),\n",
       " (427, 1.607412478367661e-06),\n",
       " (428, 2.1844584369407377e-06),\n",
       " (429, 2.956998937553759e-06),\n",
       " (430, 3.98705293837112e-06),\n",
       " (431, 5.354868832479756e-06),\n",
       " (432, 7.163813286405329e-06),\n",
       " (433, 9.546427625024893e-06),\n",
       " (434, 1.2671889390234851e-05),\n",
       " (435, 1.6755153954460764e-05),\n",
       " (436, 2.206809129549954e-05),\n",
       " (437, 2.8952975693864007e-05),\n",
       " (438, 3.783873038649e-05),\n",
       " (439, 4.9260373975413374e-05),\n",
       " (440, 6.388215916214442e-05),\n",
       " (441, 8.252493527522651e-05),\n",
       " (442, 0.00010619830176802917),\n",
       " (443, 0.00013613814762657373),\n",
       " (444, 0.00017385018823395037),\n",
       " (445, 0.00022116011304996116),\n",
       " (446, 0.00028027094046052743),\n",
       " (447, 0.0003538281360050662),\n",
       " (448, 0.0004449929823846512),\n",
       " (449, 0.0005575245896344514),\n",
       " (450, 0.0006958707972110431),\n",
       " (451, 0.0008652680424881588),\n",
       " (452, 0.0010718500489236657)]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zip(x, y)[420+1:451+2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0010718500489236657"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y[451+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
